package com.forgenet.testclient.panel;

import com.forgenet.message.base.req.ReqLoginRolePacket;
import com.forgenet.testclient.ClientMain;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginRolePanel extends JPanel implements ActionListener {

    private final JLabel playerIdLabel;
    private final JButton loginButton;

    public LoginRolePanel() {
        setLayout(new GridBagLayout());

        playerIdLabel = new JLabel("已成功登录网关: ");

        add(playerIdLabel, createGBC(0, 0));

        loginButton = new JButton("登录");
        loginButton.addActionListener(this);
        add(loginButton, createButtonGBC(0, 3));
    }

    private GridBagConstraints createButtonGBC(int x, int y) {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.gridwidth = 2; // 横跨两列（假设前面用了两列）
        gbc.insets = new Insets(10, 5, 10, 5);
        gbc.anchor = GridBagConstraints.CENTER;
        return gbc;
    }


    private GridBagConstraints createGBC(int x, int y) {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = x;
        gbc.gridy = y;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(5, 5, 5, 5);
        return gbc;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        ReqLoginRolePacket req = new ReqLoginRolePacket();
        ClientMain.channel.writeAndFlush(req);
        System.out.println("请求登录角色");
    }
}
